define( [
		'module',
		'backbone',
		'marionette'
		],
function( module, Backbone, Marionette ) {
	console.log("Loading module " + module.id + " from " + module.uri + "...");

	var SampleModel = Backbone.Model.extend({
		defaults:{
			coverImage:"img/placeholder.png",
			title:"Some title",
			author:"John Doe",
			releaseDate:"2012",
			keywords:"JavaScript Programming"
		},

		methodUrl: {
			'create': 'rest?cmd=create',
			'delete': 'rest?cmd=delete&data[id]='
		},
		/* define custom URLs for model operations. They
		 * are not REST compliant, they use the parameter
		 * cmd to identify the action requested on the server
		 */

		parse:function( response ) {
			console.log( response );
			response.id = response._id;
			console.log( response );
			return response;
		},
		/* This function allows to process the data after
		 * they come from the server. This operation
		 * is usefull if the client-side model differs 
		 * to the server model
		 */

		sync: function(method, model, options) {
			if (model.methodUrl && model.methodUrl[method.toLowerCase()]) {
				options = options || {};
				options.url = model.methodUrl[method.toLowerCase()];
			}
			if( method == "delete" ) {
				options.url += model.id;
			}
			Backbone.sync(method, model, options);
		}
		/* Override the sync method to allow custom URLs.
		 */
	});
	
	return SampleModel;
});
